﻿using Core.Utility.Helper;
using Dto.Core.Enum.Dict;
using Newtonsoft.Json;
using NPOI.POIFS.Crypt.Dsig;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Dto.Core
{
    /// <summary>
    /// 公共Dto基类
    /// <see cref="Id">自增主键</see>
    /// <see cref="Sid">雪花Id</see>
    /// <see cref="SortNumber">排序号</see>
    /// <see cref="Remark">备注</see>
    /// <see cref="CreatedBy">创建人</see>
    /// <see cref="CreatedByName">创建人名称;创建人名称冗余存储</see>
    /// <see cref="CreatedTime">创建时间</see>
    /// <see cref="UpdatedBy">更新人</see>
    /// <see cref="UpdatedByName">更新人名称;修改人名称冗余存储</see>
    /// <see cref="UpdatedTime">更新时间</see>
    /// <see cref="Revision">乐观锁;用于数据并发操作时使用,数据每次更新后，改变此值</see>
    /// <see cref="IsDeleted">删除标识;用于标识数据是否逻辑删除(软删) 0:否;1:是</see>
    /// </summary>
    public class CommonBaseDto:BaseDto,ICommonBaseDto
    {

        #region 自增主键;数据库的自增主键

        /// <summary>
        /// 自增主键;数据库的自增主键
        /// </summary>
        private long? id;

        /// <summary>
        /// 自增主键;数据库的自增主键
        /// </summary>
        [JsonProperty("id",Order = -1)]
        public virtual long? Id
        {
            get { return id; }
            set
            {
                id = value;
                OnPropertyChanged();
            }
        }

        #endregion 自增主键;数据库的自增主键

        #region 自增主键;数据库的自增主键

        /// <summary>
        /// 自增主键;数据库的自增主键
        /// </summary>
        private long? sid;

        /// <summary>
        /// 雪花Id;所有的外键均使用该字段
        /// </summary>
        [JsonProperty("sid", Order = -1)]
        public virtual long? Sid
        {
            get { return sid; }
            set
            {
                sid = value;
                OnPropertyChanged();
            }
        }

        #endregion 自增主键;数据库的自增主键

        #region 排序号

        /// <summary>
        /// 排序号
        /// </summary>
        private long? sortNumber = 1;

        /// <summary>
        /// 排序号
        /// </summary>
        [JsonProperty("sort_number",Order = int.MaxValue - 10)]
        public virtual long? SortNumber
        {
            get { return sortNumber; }
            set
            {
                sortNumber = value;
                OnPropertyChanged();
            }
        }

        #endregion 排序号

        #region 备注

        /// <summary>
        /// 备注
        /// </summary>
        private string? remark;

        /// <summary>
        /// 备注
        /// </summary>
        [JsonProperty("remark", Order = int.MaxValue - 9)]
        public virtual string? Remark
        {
            get { return remark; }
            set
            {
                remark = value;
                OnPropertyChanged();
            }
        }

        #endregion 备注

        #region 创建人

        /// <summary>
        /// 创建人
        /// </summary>
        private long? createdBy;

        /// <summary>
        /// 创建人
        /// </summary>
        [JsonProperty("created_by", Order = int.MaxValue - 8)]
        public virtual long? CreatedBy
        {
            get { return createdBy; }
            set
            {
                createdBy = value;
                OnPropertyChanged();
            }
        }

        #endregion 创建人

        #region 创建人名称;创建人名称冗余存储

        /// <summary>
        /// 创建人名称;创建人名称冗余存储
        /// </summary>
        private string? createdByName;

        /// <summary>
        /// 创建人名称;创建人名称冗余存储
        /// </summary>
        [JsonProperty("created_by_name", Order = int.MaxValue - 7)]
        public virtual string? CreatedByName
        {
            get { return createdByName; }
            set
            {
                createdByName = value;
                OnPropertyChanged();
            }
        }

        #endregion 创建人名称;创建人名称冗余存储

        #region 创建时间

        /// <summary>
        /// 创建时间
        /// </summary>
        private DateTime? createdTime;

        /// <summary>
        /// 创建时间
        /// </summary>
        [JsonProperty("created_time", Order = int.MaxValue - 6)]
        public virtual DateTime? CreatedTime
        {
            get { return createdTime; }
            set
            {
                createdTime = value;
                OnPropertyChanged();
            }
        }

        #endregion 创建时间

        #region 更新人

        /// <summary>
        /// 更新人
        /// </summary>
        private long? updatedBy;

        /// <summary>
        /// 更新人
        /// </summary>
        [JsonProperty("updated_by", Order = int.MaxValue - 5)]
        public virtual long? UpdatedBy
        {
            get { return updatedBy; }
            set
            {
                updatedBy = value;
                OnPropertyChanged();
            }
        }

        #endregion 更新人

        #region 更新人名称;修改人名称冗余存储

        /// <summary>
        /// 更新人名称;修改人名称冗余存储
        /// </summary>
        private string? updatedByName;

        /// <summary>
        /// 更新人名称;修改人名称冗余存储
        /// </summary>
        [JsonProperty("updated_by_name", Order = int.MaxValue - 4)]
        public virtual string? UpdatedByName
        {
            get { return updatedByName; }
            set
            {
                updatedByName = value;
                OnPropertyChanged();
            }
        }

        #endregion 更新人名称;修改人名称冗余存储

        #region 更新时间

        /// <summary>
        /// 更新时间
        /// </summary>
        private DateTime? updatedTime;

        /// <summary>
        /// 更新时间
        /// </summary>
        [JsonProperty("updated_time", Order = int.MaxValue - 3)]
        public virtual DateTime? UpdatedTime
        {
            get { return updatedTime; }
            set
            {
                updatedTime = value;
                OnPropertyChanged();
            }
        }

        #endregion 更新时间

        #region 乐观锁;用于数据并发操作时使用,数据每次更新后，改变此值

        /// <summary>
        /// 乐观锁;用于数据并发操作时使用,数据每次更新后，改变此值
        /// </summary>
        private string? revision;

        /// <summary>
        /// 乐观锁;用于数据并发操作时使用,数据每次更新后，改变此值
        /// </summary>
        [JsonProperty("revision", Order = int.MaxValue - 2)]
        public virtual string? Revision
        {
            get { return revision; }
            set
            {
                revision = value;
                OnPropertyChanged();
            }
        }

        #endregion 乐观锁;用于数据并发操作时使用,数据每次更新后，改变此值

        #region 删除说明
        /// <summary>
        /// 删除说明
        /// </summary>
        private string? deletedDescription;

        /// <summary>
        /// 删除说明
        /// </summary>
        [JsonProperty("deleted_description")]
        [Display(Name = "删除说明")]
        public string? DeletedDescription
        {
            get { return deletedDescription; }
            set
            {
                deletedDescription = value;
                OnPropertyChanged();
            }
        }
        #endregion 删除说明
        
        #region 删除标识;用于标识数据是否逻辑删除(软删) 0:否;1:是

        /// <summary>
        /// 删除标识;用于标识数据是否逻辑删除(软删) 0:否;1:是
        /// </summary>
        private int? isDeleted = 0;

        /// <summary>
        /// 删除标识;用于标识数据是否逻辑删除(软删) 0:否;1:是
        /// </summary>
        [JsonProperty("is_deleted", Order = int.MaxValue - 1)]
        public virtual int? IsDeleted
        {
            get { return isDeleted; }
            set
            {
                isDeleted = value;
                OnPropertyChanged();
            }
        }

        #endregion 删除标识;用于标识数据是否逻辑删除(软删) 0:否;1:是

        /// <summary>
        /// 初始化复制新增数据
        /// </summary>
        public virtual void InitCopyAddData()
        {
            this.DtoMode = DtoMode.Insert;
            this.Id = null;
            this.Sid = null;
            this.CreatedBy = null;
            this.CreatedByName = null;
            this.CreatedTime = null;
            this.UpdatedBy = null;
            this.UpdatedByName = null;
            this.UpdatedTime = null;
            this.DeletedDescription = null;
            this.IsDeleted = YesOrNoDictEnum.No.ToInt();
            this.Revision = null;
        }
    }


    /// <summary>
    /// 
    /// </summary>
    public interface ICommonBaseDto: IBaseDto
    {
        /// <summary>
        /// 自增主键;数据库的自增主键
        /// </summary>
        [JsonProperty("id", Order = -1)]
        public long? Id { get; set; }

        /// <summary>
        /// 雪花Id;所有的外键均使用该字段
        /// </summary>
        [JsonProperty("sid", Order = -2)]
        public long? Sid { get; set; }

        /// <summary>
        /// 排序号
        /// </summary>
        [JsonProperty("sort_number", Order = int.MaxValue - 10)]
        public long? SortNumber { get; set; }

        /// <summary>
        /// 备注
        /// </summary>
        [JsonProperty("remark", Order = int.MaxValue - 9)]
        public string? Remark { get; set; }

        /// <summary>
        /// 创建人
        /// </summary>
        [JsonProperty("created_by", Order = int.MaxValue - 8)]
        public long? CreatedBy { get; set; }

        /// <summary>
        /// 创建人名称;创建人名称冗余存储
        /// </summary>
        [JsonProperty("created_by_name", Order = int.MaxValue - 7)]
        public string? CreatedByName { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        [JsonProperty("created_time", Order = int.MaxValue - 6)]
        public DateTime? CreatedTime { get; set; }

        /// <summary>
        /// 更新人
        /// </summary>
        [JsonProperty("updated_by", Order = int.MaxValue - 5)]
        public long? UpdatedBy { get; set; }

        /// <summary>
        /// 更新人名称;修改人名称冗余存储
        /// </summary>
        [JsonProperty("updated_by_name", Order = int.MaxValue - 4)]
        public string? UpdatedByName { get; set; }

        /// <summary>
        /// 更新时间
        /// </summary>
        [JsonProperty("updated_time", Order = int.MaxValue - 3)]
        public DateTime? UpdatedTime { get; set; }

        /// <summary>
        /// 乐观锁;用于数据并发操作时使用,数据每次更新后，改变此值
        /// </summary>
        [JsonProperty("revision", Order = int.MaxValue - 2)]
        public string? Revision { get; set; }

        /// <summary>
        /// 删除标识;用于标识数据是否逻辑删除(软删) 0:否;1:是
        /// </summary>
        [JsonProperty("is_deleted", Order = int.MaxValue - 1)]
        public int? IsDeleted { get; set; }

        /// <summary>
        /// 初始化复制新增数据
        /// </summary>
        public void InitCopyAddData();
    }
}
